package com.edu.dgut.dao;

import com.edu.dgut.entity.administratorsEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

public interface administratorsRepository extends JpaRepository<administratorsEntity,String> {

    //通过姓名模糊查找管理员
    List<administratorsEntity> findByNameLike(String name);

    //通过姓名查找管理员
    administratorsEntity findByName(String name);

    //通过account查询管理员信息
    administratorsEntity findByAccount(int account);

    //查找最大工号
    @Query("select d.account from administratorsEntity d where d.account = (select MAX(a.account) from administratorsEntity a)")
    int findAccount();

    //插入或修改管理员信息
    administratorsEntity save(administratorsEntity administrator);

    //删除一条管理员信息
    @Transactional
    int deleteByAccount(int account);
}
